package com.honey.solr.schema;

import com.honey.compilation.xml.Document;
import com.honey.compilation.xml.XmlElement;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Schema;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.solr.SolrFactory;
import com.honey.solr.schema.node.CopyField;
import com.honey.solr.schema.node.DefaultSearchField;
import com.honey.solr.schema.node.Fields;
import com.honey.solr.schema.node.SolrQueryParser;
import com.honey.solr.schema.node.Types;
import com.honey.solr.schema.node.UniqueKey;

public class SolrSchema  {
	
	private SolrFactory solrFactory;
	
	public SolrSchema(SolrFactory solrFactory) {
		this.solrFactory = solrFactory;
	}
	
	public Document getDocument(){
		FullyQualifiedJavaType type = new FullyQualifiedJavaType("schema");
		Document answer = new Document(type);
		XmlElement rootElement = new XmlElement("schema");
		rootElement.addAttribute("version","1.5");
		rootElement.addAttribute("name",solrFactory.getSchemaName());
		
		appendElement(rootElement, solrFactory);
		answer.setRootElement(rootElement);
		
		return answer ;
	}
	
	private void appendElement(XmlElement parent,SolrFactory solrFactory){
		new Types(solrFactory).appendChildNode(parent);
		new Fields(solrFactory).appendChildNode(parent);
		new UniqueKey(solrFactory).appendChildNode(parent);
		new DefaultSearchField().appendChildNode(parent);
		new SolrQueryParser().appendChildNode(parent);
		new CopyField(solrFactory).appendChildNode(parent);;
	}
}
